package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.system.dto.CollectTimeFeeCeshiBo;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCollectTimeVo;
import com.ruoyi.system.bo.ZsyyCollectTimeQueryBo;
import com.ruoyi.system.bo.ZsyyCollectTimeAddBo;
import com.ruoyi.system.bo.ZsyyCollectTimeEditBo;
import com.ruoyi.system.service.IZsyyCollectTimeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 计费规则时段Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "计费规则时段控制器", tags = {"计费规则时段管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/collectTime")
public class ZsyyCollectTimeController extends BaseController {

    private final IZsyyCollectTimeService iZsyyCollectTimeService;

    /**
     * 查询计费规则时段列表
     */
    @ApiOperation("查询计费规则时段列表")
    @PreAuthorize("@ss.hasPermi('system:collectTime:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCollectTimeVo> list(@Validated ZsyyCollectTimeQueryBo bo) {
        return iZsyyCollectTimeService.queryPageList(bo);
    }

    /**
     * 导出计费规则时段列表
     */
    @ApiOperation("导出计费规则时段列表")
    @PreAuthorize("@ss.hasPermi('system:collectTime:export')")
    @Log(title = "计费规则时段", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCollectTimeVo> export(@Validated ZsyyCollectTimeQueryBo bo) {
        List<ZsyyCollectTimeVo> list = iZsyyCollectTimeService.queryList(bo);
        ExcelUtil<ZsyyCollectTimeVo> util = new ExcelUtil<ZsyyCollectTimeVo>(ZsyyCollectTimeVo.class);
        return util.exportExcel(list, "计费规则时段");
    }

    /**
     * 获取计费规则时段详细信息
     */
    @ApiOperation("获取计费规则时段详细信息")
    @PreAuthorize("@ss.hasPermi('system:collectTime:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyCollectTimeVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyCollectTimeService.queryById(id));
    }

    /**
     * 新增计费规则时段
     */
    @ApiOperation("新增计费规则时段")
    @PreAuthorize("@ss.hasPermi('system:collectTime:add')")
    @Log(title = "计费规则时段", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCollectTimeAddBo bo) {
        return toAjax(iZsyyCollectTimeService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改计费规则时段
     */
    @ApiOperation("修改计费规则时段")
    @PreAuthorize("@ss.hasPermi('system:collectTime:edit')")
    @Log(title = "计费规则时段", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCollectTimeEditBo bo) {
        return toAjax(iZsyyCollectTimeService.updateByEditBo(bo) ? 1 : 0);
    }
    /**
     * 修改计费规则时段
     */
    @ApiOperation("费用测算")
    @PreAuthorize("@ss.hasPermi('system:collectTime:feeCeshi')")
    @Log(title = "费用测算", businessType = BusinessType.OTHER)
    @RepeatSubmit
    @PostMapping("/ceshiCollectTime")
    public AjaxResult ceshiCollectTime(@Validated @RequestBody CollectTimeFeeCeshiBo bo) {
		return AjaxResult.success(iZsyyCollectTimeService.ceshiCollectTime(bo));
    }

    /**
     * 删除计费规则时段
     */
    @ApiOperation("删除计费规则时段")
    @PreAuthorize("@ss.hasPermi('system:collectTime:remove')")
    @Log(title = "计费规则时段" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyCollectTimeService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
